#!/usr/bin/python3
# -*- coding: utf-8 -*-

"""
PyQt5 tutorial

This example draws 9 rectangles in different
brush styles.

author: py40.com
last edited: 2017年3月
"""

import sys
from PyQt5.QtWidgets import QWidget, QApplication
from PyQt5.QtGui import QPainter, QBrush
from PyQt5.QtCore import Qt


class Example(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        self.setGeometry(300, 300, 500, 300)
        self.setWindowTitle('draw rect & brushe')
        self.show()

    def paintEvent(self, e):
        qp = QPainter()
        qp.begin(self)
        self.drawBrushes(qp)
        qp.end()

    def drawBrushes(self, qp):
        brush = QBrush(Qt.blue,Qt.SolidPattern)
        qp.setBrush(brush)
        qp.drawRect(50, 0, 100, 100)

        brush.setStyle(Qt.Dense1Pattern)
        qp.setBrush(brush)
        qp.drawRect(200, 0, 100, 100)

        brush.setStyle(Qt.Dense2Pattern)
        qp.setBrush(brush)
        qp.drawRect(350, 0, 100, 100)

        brush.setStyle(Qt.DiagCrossPattern)
        qp.setBrush(brush)
        qp.drawRect(50, 100, 100, 100)

        brush.setStyle(Qt.Dense5Pattern)
        qp.setBrush(brush)
        qp.drawRect(200, 100, 100, 100)

        brush.setStyle(Qt.Dense6Pattern)
        qp.setBrush(brush)
        qp.drawRect(350, 100, 100, 100)

        brush.setStyle(Qt.HorPattern)
        qp.setBrush(brush)
        qp.drawRect(50, 200, 100, 100)

        brush.setStyle(Qt.VerPattern)
        qp.setBrush(brush)
        qp.drawRect(200, 200, 100, 100)

        brush.setStyle(Qt.BDiagPattern)
        qp.setBrush(brush)
        qp.drawRect(350, 200, 100, 100)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())
